home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / src / Rkm_asm.lha / Assembly_Codes / OS_Sources / Handler / RemoveNH.s < prev    next >
Text File  |  1992-09-02  |  3KB  |  165 lines

  1.  
  2.  * Memory Buffer addresses.
  3.  *
  4.  *  0  Startup Return Message
  5.  *  4 Task address
  6.  *  8 KILL NUMERICPAD Port
  7.  * 12 NUMERICPAD Message
  8.  
  9.     INCDIR    WORK:Include/
  10.  
  11.     INCLUDE    work:devpac/large.gs
  12.     INCLUDE    misc/missing_keys.i
  13.  
  14.     lea    membuf(pc),a4
  15.  
  16.     suba.l    a1,a1
  17.     move.l    4.w,a6
  18.     jsr    _LVOFindTask(a6)
  19.     tst.l    d0
  20.     beq    exit
  21.     move.l    d0,a5
  22.     move.l    a5,4(a4)
  23.     tst.l    pr_CLI(a5)        ; Was this task started from CLI?
  24.     bne.s    _main            ; Yes.
  25.     lea    pr_MsgPort(a5),a0    ; No. From Workbench.
  26.     jsr    _LVOWaitPort(a6)
  27.     lea    pr_MsgPort(a5),a0
  28.     jsr    _LVOGetMsg(a6)
  29.     move.l    d0,(a4)            ; D0 = A WBStartup Message.
  30.  
  31. _main
  32.  
  33.  * Set-Up a Message Port.
  34.  
  35.         jsr    _LVOForbid(a6)
  36.         lea     portname(pc),a1
  37.         jsr    _LVOFindPort(a6)
  38.         tst.l   d0
  39.     bne    exists
  40.         moveq   #MP_SIZE,d0
  41.         move.l  #MEMF_PUBLIC!MEMF_CLEAR,d1
  42.         jsr    _LVOAllocMem(a6)
  43.         move.l  d0,8(a4)
  44.         beq    no_pmem
  45.         move.l  d0,a0
  46.         clr.l    (a0)                ; LN_SUCC(a0)
  47.         clr.l    LN_PRED(a0)
  48.         move.b  #NT_MSGPORT,LN_TYPE(a0)
  49.         clr.b    LN_PRI(a0)
  50.         lea     portname(pc),a1
  51.         move.l  a1,LN_NAME(a0)
  52.         move.b  #PA_SIGNAL,MP_FLAGS(a0)
  53.         move.l  4(a4),MP_SIGTASK(a0)
  54.         moveq    #-1,d0
  55.         jsr    _LVOAllocSignal(a6)
  56.         move.b  d0,d5
  57.         cmp.l    #-1,d0
  58.         bne.s    ad_port
  59.         jsr    _LVOPermit(a6)
  60.     bra    fr_pmem
  61. ad_port    move.l    8(a4),a1
  62.         move.b  d5,MP_SIGBIT(a1)
  63.         jsr    _LVOAddPort(a6)
  64.         jsr    _LVOPermit(a6)
  65.  
  66.  * Set-Up the Message.
  67.  
  68.     moveq    #pm_SIZEOF,d0
  69.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  70.     jsr    _LVOAllocMem(a6)
  71.     move.l    d0,12(a4)
  72.     beq.s    free_port
  73.     move.l    d0,a0
  74.     clr.l    (a0)                ; LN_SUCC(a0)
  75.     clr.l    LN_PRED(a0)
  76.     move.b    #NT_MESSAGE,LN_TYPE(a0)
  77.     clr.b    LN_PRI(a0)
  78.     clr.l    LN_NAME(a0)
  79.     move.l    8(a4),MN_REPLYPORT(a0)
  80.     move.w    #pm_SIZEOF,MN_LENGTH(a0)
  81.  
  82.  * The start of NUMERICPAD Message data.
  83.  
  84.     move.w    #PMCOMMAND_QUIT,pm_Command(a0)
  85.  
  86.     bra.s    find_port
  87.  
  88. exists    jsr    _LVOPermit(a6)
  89.         bra.s    quit
  90.  
  91. no_pmem    jsr    _LVOPermit(a6)
  92.         bra.s    quit
  93.  
  94. find_port
  95.     jsr    _LVOForbid(a6)
  96.     lea    otherport(pc),a1
  97.     jsr    _LVOFindPort(a6)    ; Check if `NUMERICPAD Port' exists?
  98.     tst.l    d0
  99.     bne.s    send_msg
  100.     jsr    _LVOPermit(a6)
  101.     bra.s    free_message
  102.  
  103. send_msg
  104.     move.l    d0,a0
  105.     move.l    12(a4),a1
  106.     jsr    _LVOPutMsg(a6)
  107.     jsr    _LVOPermit(a6)
  108.  
  109.     move.l    8(a4),a0
  110.     jsr    _LVOWaitPort(a6)    ; Wait for `NUMERICPAD Port' to reply
  111.     move.l    8(a4),a0
  112.     jsr    _LVOGetMsg(a6)        ; get `NUMERICPAD Port' Message
  113.  
  114.  * You do not ReplyMsg() as you (this port) initiated the Message.
  115.  
  116.  
  117. free_message
  118.     move.l    12(a4),a1
  119.     moveq    #pm_SIZEOF,d0
  120.     jsr    _LVOFreeMem(a6)
  121.  
  122. free_port
  123.     move.l    8(a4),a0
  124.     tst.l    a0
  125.         beq.s    quit
  126.     move.l    4.w,a6
  127.         tst.b    MP_SIGBIT(a0)
  128.         beq.s    no_sig
  129.         jsr    _LVOFreeSignal(a6)
  130. no_sig    move.l    8(a4),a1
  131.         jsr    _LVORemPort(a6)
  132. fr_pmem    move.l    8(a4),a1
  133.         moveq   #MP_SIZE,d0
  134.     move.l    4.w,a6
  135.         jsr    _LVOFreeMem(a6)
  136.  
  137. quit    move.l  #8000000,d0
  138.         moveq    #MEMF_CHIP,d1
  139.     jsr    _LVOAllocMem(a6)
  140.     tst.l    d0
  141.     beq.s    cleanup
  142.     move.l    d0,a1
  143.     move.l    #8000000,d0
  144.     jsr    _LVOFreeMem(a6)
  145. cleanup    tst.l    (a4)
  146.     beq.s    exit            ; Exit - Task was started from CLI.
  147.     jsr    _LVOForbid(a6)
  148.     move.l    (a4),a1            ; Reply to the WB Startup Message and
  149.     jsr    _LVOReplyMsg(a6)    ; Exit - Task was started from WB.
  150. exit    moveq    #0,d0
  151.     rts
  152.  
  153.  
  154.  * String Variables.
  155.  
  156. int_name    dc.b    'intuition.library',0
  157. dos_name    dc.b    'dos.library',0
  158. icon_name       dc.b    'icon.library',0,0
  159. portname        dc.b    'KILL NUMERICPAD Port',0,0
  160. otherport    dc.b    'NUMERICPAD Port',0
  161.  
  162.  
  163.  * Buffer Variables.
  164.  
  165. membuf        dcb.b    20,0